<template>
    <div>
      <Main_header></Main_header>
      <div class="common">
        <div class="content">
        <!--全部商品图片展示-->
        <div class="contentImg">
          <div class="title">
            <h2>全部商品</h2>
            <div>
            </div>
          </div>
          <div>
            <el-row>
              <el-col :span="6" v-for="(good,index) in goodList" :key="index">
                <el-card :body-style="{ padding: '0px' }" shadow="hover">
                  <img :src="good.imgurl" @click="toDetail(good,index)" style="width: 100%;height: 250px">
                  <div style="padding: 14px">
                    <span class="messages">{{good.goodName}}</span>
                    <span class="description">{{good.description}}</span>
                    <div class="bottom clearfix">
                      <div class="good-item">
                        ￥{{good.rentPriceHour}}/小时~￥{{good.rentPriceDay}}/天
                      </div>
                      <!--<el-button type="text" class="button">操作按钮</el-button>-->
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
      </div>
      <Main_footer style="margin:0 auto"></Main_footer>
    </div>
</template>

<script>
  import Main_header from '../../components/main/Main_header'
  import Main_footer from '../../components/main/Main_footer'
  export default {
    name: 'AllGood',
    components: {
      Main_footer,
      Main_header
    },
    data(){
      return{
        goodList:[],
      }
    },
    mounted(){
      this.initAllGood();
    },
    methods:{
      toDetail(good,index) {
        this.$router.push({
          path: '/detail',
          name: 'Detail',
          params: {
            name: good.goodId,
          }
        })

      },
      selectGood(){
        // 取到从导航组件的路由带过来的参数
        let routerParams = this.$route.params.name;
        let categoryName = this.$route.params.category;
        console.log('我过来了selectKey_'+routerParams);
        console.log('我过来了selectKey_'+categoryName);
        let url = '/good/data/rent/some/?selectKey='+routerParams+'&&uploadStatus='+1+'&&userId='+''+'&&status='+1+'&&categoryName='+categoryName;
        this.postRequest(url).then(resp=> {
          if (resp.length>0) {
            console.log(resp)
            this.goodList='';
            this.goodList=resp;
            this.$notify.success({ title: '成功', message: '查询成功' });
            // routerParams='';
          }else{
            this.$notify.info({ title: '信息', message: '啥也没有' });
          }
        })


      },
    //查询全部数据
    initAllGood () {
      if (this.$route.params.name||this.$route.params.category) {
        this.selectGood()
      }else {
        this.goodList='';
        this.postRequest('/all/goodList').then(resp => {
          if (resp) {
            console.log(resp);
            this.goodList=resp;
          }
        })
      }
    },
    },
  }
</script>

<style scoped>
  .common{
    width: 70%;
    margin: 50px auto;
  }
  .content{
    width: 100%;
  }
  .contentImg{
    width: 100%;
  }

</style>
